package org.example.cake.controller;
import org.example.cake.common.Rep;
import org.example.cake.entity.Themecake;
import org.example.cake.service.ThemecakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/themecake")
public class ThemecakeController {
    @Autowired
    private ThemecakeService themecakeService;

    /**
     * 查询所有主题蛋糕
     * @return 主题集合
     */
    @GetMapping("/selectAllTheme")
    public Rep selectAllTheme(){
        List<Themecake> themecakeList = this.themecakeService.selectAllTheme();
        return new Rep().addData("themecakeList", themecakeList);
    }

    /**
     * 添加主题蛋糕
     * @param themecake
     * @return
     */
    @PostMapping("/insert")
    public Rep  insert(@RequestBody Themecake themecake){
        this.themecakeService.insert(themecake);
        return new Rep();
    }

    /**
     * 删除主题蛋糕
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Rep delete(Integer id){
        this.themecakeService.deleteByPrimaryKey(id);
        return new Rep();
    }

    /**
     * 修改主题蛋糕
     * @param themecake
     * @return
     */
    @PostMapping("/update")
    public Rep update(@RequestBody Themecake themecake) {
        this.themecakeService.updateByPrimaryKey(themecake);
        return new Rep();
    }


    /**
     * 根据id查询主题信息
     * @param id 主题id
     * @return 主题蛋糕对象
     */
    @GetMapping("/selectById")
    public Rep selectById(@RequestParam("id") Integer id){
        Themecake selectById = this.themecakeService.selectById(id);
        return new Rep().addData("data", selectById);
    }


}
